<template>
    <section>
        <el-col :span="24">
            <el-form inline>
                <el-form-item>
                    <el-input size="small" v-model.trim="form.number" style="width: 150px" placeholder="核价单编码" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input size="small" v-model.trim="form.type_no" style="width: 150px;" placeholder="款号" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-select size="small" v-model="form.state" placeholder="状态" style="width: 100px" clearable>
                        <el-option value="0" label="正常"></el-option>
                        <el-option value="1" label="锁定"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-popover placement="bottom" width="450" trigger="click">
                        <el-form label-width="80px" label-position="left">
                            <el-form-item label="款名">
                                <el-input size="small" v-model.trim="form.type_name" style="width: 80%;" placeholder="款名" clearable></el-input>
                            </el-form-item>
                            <el-form-item label="核价用途">
                                <el-select size="small" v-model="form.t73_id" placeholder="核价用途" style="width: 80%" clearable>
                                    <el-option value="1" label="大货核价"></el-option>
                                    <el-option value="2" label="过审核价"></el-option>
                                    <el-option value="3" label="成本预估核价"></el-option>
                                    <el-option value="4" label="实付核价"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="创建人">
                                <el-input v-model.trim="form.creator" size="small" style="width: 80%;" placeholder="创建人" clearable></el-input>
                            </el-form-item>
                        </el-form>
                        <el-badge :is-dot="(form.type_name!=='' || form.t73_id!=='' || form.creator!=='')" slot="reference" class="more-btn">
                            <el-button size="small" type="warning" plain>更多</el-button>
                        </el-badge>
                    </el-popover>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" class="el-icon-search" @click="searchBtn" size="small" :loading="loading">查询</el-button>
                    <el-button type="warning" class="el-icon-plus" size="small" @click="addBtn" :disabled="!nodeActions.includes('add')">新增</el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <el-col :span="24">
            <el-table :data="data" style="width: 100%" :max-height="tableHeight" v-loading="loading" size="mini" row-key="id" highlight-current-row
                      :header-cell-style="headerCellStyle">
                <el-table-column prop="state" label="锁定状态" width="90">
                    <template slot-scope="{row}">
                        <el-tag class="el-icon-lock" size="mini" v-if="row.state==1" type="danger">已锁定</el-tag>
                        <el-tag class="el-icon-unlock" size="mini" v-else-if="row.state==0" type="info">未锁定</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="核价单编码" prop="number" width="100"></el-table-column>
                <el-table-column label="图片" width="50">
                    <template slot-scope="{row}">
                        <el-image v-if="row.img" :src="row.img" :preview-src-list="[row.img]" style="height: 30px;" fit="contain"></el-image>
                    </template>
                </el-table-column>
                <el-table-column prop="style_number" label="款号" width="110">
                    <template slot-scope="{row}">
                        <el-button type="text" style="color: #909399" size="small" class="el-icon-document-copy copy-type-no"
                                   @click="copyBtn('.copy-type-no', row.style_number)"></el-button>
                        <a @click="linkTo(row.style_number, 'pages_designEd')" style="color: #409eff">
                            {{row.style_number}}
                        </a>
                    </template>
                </el-table-column>
                <el-table-column label="款名" prop="style" width="120" show-overflow-tooltip></el-table-column>
                <el-table-column label="核价用途" prop="t73_id" width="95">
                    <template slot-scope="{row}">
                        <el-tag size="mini" v-if="row.t73_id == 1" type="primary">大货核价</el-tag>
                        <el-tag size="mini" v-else-if="row.t73_id == 2" type="info">过审核价</el-tag>
                        <el-tag size="mini" v-else-if="row.t73_id == 3" type="warning">成本预估核价</el-tag>
                        <el-tag size="mini" v-else-if="row.t73_id == 4" type="success">实付核价</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="颜色" prop="colour" width="80"></el-table-column>
                <el-table-column label="管理费率" prop="f61" width="70">
                    <template slot-scope="{row}">
                        {{parseFloat(row.f61)}}
                    </template>
                </el-table-column>
                <el-table-column label="成衣成本加价总价" prop="f65" width="120">
                    <template slot-scope="{row}">
                        {{parseFloat(row.f65)}}
                    </template>
                </el-table-column>
                <el-table-column label="绣花成本加价总价" prop="f63" width="120">
                    <template slot-scope="{row}">
                        {{parseFloat(row.f63)}}
                    </template>
                </el-table-column>
                <el-table-column label="成本加价总价" prop="f67" width="120">
                    <template slot-scope="{row}">
                        {{parseFloat(row.f67)}}
                    </template>
                </el-table-column>
                <el-table-column label="其他费用加价总价" prop="f75" width="120">
                    <template slot-scope="{row}">
                        {{parseFloat(row.f75)}}
                    </template>
                </el-table-column>
                <el-table-column label="备注" prop="comment" show-overflow-tooltip></el-table-column>
                <el-table-column label="创建人" prop="creator" width="80"></el-table-column>
                <el-table-column label="创建时间" prop="creation_time" width="90"></el-table-column>
                <el-table-column label="操作" fixed="right" width="150">
                    <template slot-scope="{row}">
                        <el-button type="text" size="small" class="el-icon-folder-opened" @click="editBtn(row)">&nbsp;打开</el-button>
                        &nbsp;
                        <el-dropdown trigger="hover" style="font-size: 12px;" @command="actionBtn($event, row)">
                            <span style="cursor: pointer;color: #409EFF;">
                                更多操作<i class="el-icon-arrow-down el-icon--right"></i>
                            </span>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item command="LOCK" icon="el-icon-lock" :disabled="!(nodeActions.includes('lock') && row.state==0)">锁 定</el-dropdown-item>
                                <el-dropdown-item command="UNLOCK" icon="el-icon-unlock" :disabled="!(nodeActions.includes('unlock') && row.state==1)">解 锁</el-dropdown-item>
                                <el-dropdown-item command="COPY" icon="el-icon-document-copy" :disabled="!(nodeActions.includes('edit'))">复 制</el-dropdown-item>
                                <el-dropdown-item command="DEL" icon="el-icon-delete" :disabled="!(nodeActions.includes('del') && row.state==0)">删 除</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                    </template>
                </el-table-column>
            </el-table>
            <!--翻页栏-->
            <div style="margin-top: 4px;overflow: hidden;float: right;">
                <Page :total="total" :current="page" :page-size="limit" show-total @on-change="pageChange"></Page>
            </div>
        </el-col>

        <!--详情-->
        <el-drawer :title="editTitle" :visible.sync="editVisible" size="1200px" direction="rtl" :wrapperClosable="false" :before-close="closeBtn">
            <el-row style="padding: 0 0 10px 0px">
                <div style="margin-bottom: 10px;padding-left: 10px;">
                    <svg t="1717659283335" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9445" width="20" height="20"><path d="M407.466667 477.866667h-277.333334C93.866667 477.866667 64 448 64 409.6v-277.333333c0-36.266667 29.866667-66.133333 66.133333-66.133334h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133334v277.333333c2.133333 38.4-27.733333 68.266667-66.133333 68.266667zM132.266667 108.8c-12.8 0-25.6 10.666667-25.6 25.6v277.333333c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333333c0-12.8-10.666667-25.6-25.6-25.6h-277.333333zM407.466667 960h-277.333334C93.866667 960 64 930.133333 64 893.866667v-277.333334c0-36.266667 29.866667-66.133333 66.133333-66.133333h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM132.266667 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z m618.666666-110.933333c-17.066667 0-34.133333-6.4-46.933333-19.2L563.2 320c-12.8-12.8-19.2-29.866667-19.2-46.933333s6.4-34.133333 19.2-46.933334L704 83.2c12.8-12.8 29.866667-19.2 46.933333-19.2 17.066667 0 34.133333 6.4 46.933334 19.2l140.8 140.8c12.8 12.8 19.2 29.866667 19.2 46.933333 0 17.066667-6.4 34.133333-19.2 46.933334l-138.666667 142.933333c-12.8 12.8-29.866667 19.2-49.066667 19.2z m0-373.333333c-6.4 0-12.8 2.133333-17.066666 6.4l-140.8 140.8c-4.266667 4.266667-6.4 10.666667-6.4 17.066666 0 6.4 2.133333 12.8 6.4 17.066667l140.8 140.8c4.266667 4.266667 10.666667 6.4 17.066666 6.4 6.4 0 12.8-2.133333 17.066667-6.4l140.8-140.8c4.266667-4.266667 6.4-10.666667 6.4-17.066667 0-6.4-2.133333-12.8-6.4-17.066666L768 113.066667c-4.266667-4.266667-8.533333-6.4-17.066667-6.4z m138.666667 853.333333h-277.333333c-36.266667 0-66.133333-29.866667-66.133334-66.133333v-277.333334c0-36.266667 29.866667-66.133333 66.133334-66.133333h277.333333c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM614.4 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z" fill="#1E87EB" p-id="9446"></path></svg>
                    <span style="font-size: 18px;font-weight: bold;vertical-align: bottom;margin-left: 4px;">编号：{{editForm.number}}</span>
                    <el-tag class="el-icon-lock" size="mini" v-if="editForm.state==1" type="danger" style="vertical-align: super;margin-left: 10px;">已锁定</el-tag>
                    <el-dropdown v-if="editForm.id" trigger="click" style="position: absolute;right: 10px;" @command="printBtn">
                        <el-button type="warning" class="el-icon-printer" size="small" plain :loading="btnLoading">
                            打印
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item icon="el-icon-printer" command="DESIGN:2.3">成本预估核价单（2.3倍率）</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-printer" command="DESIGN:2.5">成本预估核价单（2.5倍率）</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-printer" command="DESIGN:2.6">成本预估核价单（2.6倍率）</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-printer" command="DESIGN:2.8">成本预估核价单（2.8倍率）</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-printer" command="DESIGN:2.85">成本预估核价单（2.85倍率）</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-printer" command="DESIGN:3">成本预估核价单（3倍率）</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-printer" command="DESIGN:3.4">成本预估核价单（3.4倍率）</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-printer" command="SUPPLIER">加工厂核价单（厂供）</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
                <el-row style="padding-left: 10px;">
                    <el-col :span="3">
                        <el-image v-if="editForm.img" :src="editForm.img" fit="contain" style="width: 120px;height: 250px;"></el-image>
                        <svg v-else t="1718681716906" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2623" width="100" height="100"><path d="M400.696 268.795c-17.249 0-31.233 13.986-31.233 31.233v30.471c0 17.249 13.986 31.233 31.233 31.233s31.233-13.986 31.233-31.233v-30.471c0-17.249-13.985-31.233-31.233-31.233z" fill="#999999" p-id="2624"></path><path d="M623.649 361.734c17.249 0 31.234-13.986 31.234-31.233v-30.471c0-17.249-13.986-31.233-31.234-31.233s-31.233 13.986-31.233 31.233v30.471c-0.001 17.248 13.985 31.233 31.233 31.233z" fill="#999999" p-id="2625"></path><path d="M438.295 388.804c-14.656 9.104-19.155 28.362-10.050 43.013 11.209 18.047 41.976 48.59 86.157 48.59 43.958 0 75.1-30.313 86.574-48.223 9.303-14.529 5.068-33.847-9.455-43.15-14.539-9.298-33.852-5.068-43.15 9.455-0.122 0.199-13.38 19.45-33.969 19.45-20.009 0-32.444-18.128-33.278-19.373-9.166-14.423-28.28-18.805-42.829-9.761z" fill="#999999" p-id="2626"></path><path d="M824.508503 116.690676 571.592236 116.690676c-17.248849 0-31.233352 13.985526-31.233352 31.233352s13.985526 31.233352 31.233352 31.233352l252.916267 0c40.181141 0 72.878844 32.692586 72.878844 72.878844l0 396.966057-189.334159-165.29465c-12.20088-10.655687-30.517037-10.207479-42.173518 0.9967L468.578048 674.16231 309.521472 517.519714c-11.895935-11.70253-30.903847-12.002358-43.154869-0.645706L126.957507 646.163629l0-394.126382c0-40.186258 32.692586-72.878844 72.878844-72.878844l252.916267 0c17.248849 0 31.233352-13.985526 31.233352-31.233352S470.000444 116.690676 452.751594 116.690676L199.836351 116.690676c-74.632791 0-135.346571 60.71378-135.346571 135.346571l0 520.56405c0 74.632791 60.71378 135.346571 135.346571 135.346571l252.916267 0c17.248849 0 31.233352-13.985526 31.233352-31.233352s-13.985526-31.233352-31.233352-31.233352L199.836351 845.481164c-40.186258 0-72.878844-32.692586-72.878844-72.878844l0-41.23924 160.003134-148.385539 159.428036 157.007917c12.048407 11.865235 31.361265 11.981892 43.546795 0.274246l198.576661-190.68697 208.876238 182.346001 0 40.683585c0 40.186258-32.697703 72.878844-72.878844 72.878844L571.592236 845.481164c-17.248849 0-31.233352 13.985526-31.233352 31.233352s13.985526 31.233352 31.233352 31.233352l252.916267 0c74.627674 0 135.346571-60.71378 135.346571-135.346571L959.855074 252.037247C959.855074 177.404456 899.136178 116.690676 824.508503 116.690676z" fill="#999999" p-id="2627"></path></svg>
                    </el-col>
                    <el-col :span="21" style="padding-left: 1px;">
                        <el-form inline label-position="right" label-width="90px">
                            <el-form-item label="设计款号：" class="edit-item-form">
                                <el-select v-model.trim="editForm.import_number" filterable remote placeholder="输入搜索设计款号" size="small" style="width: 160px;"
                                           :remote-method="searchTypeNoBtn" @change="typeNoChangeBtn" :disabled="!(isEdit && !editForm.id)">
                                    <el-option v-for="(item,index) in styleList" :label="item.style.number"
                                               :value="item.style.number+' '+item.label+' '+item.colour" :key="index" >
                                        <span style="float: left">{{ item.style.number }}</span>
                                        <span style="margin-left: 40px;"></span>
                                        <span style="float:right; color: #8492a6; font-size: 13px">
                                            {{item.label}}&nbsp;&nbsp;{{item.colour}}
                                        </span>
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="设计款名：">
                                <el-input size="small" style="width: 160px" v-model="editForm.style" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="设计颜色：">
                                <el-input size="small" style="width: 160px" v-model="editForm.colour" disabled></el-input>
                            </el-form-item>
                            <el-form-item label="核价用途：" class="edit-item-form">
                                <el-select size="small" v-model="editForm.t73_id" placeholder="核价用途" style="width: 160px" clearable :disabled="!isEdit">
                                    <el-option :value=1 label="大货核价"></el-option>
                                    <el-option :value=2 label="过审核价"></el-option>
                                    <el-option :value=3 label="成本预估核价"></el-option>
                                    <el-option :value=4 label="实付核价"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-form>
                        <el-form inline class="verify-price-box" label-position="right" label-width="100px">
                            <el-form-item label="主料总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f69)}}</div>
                            </el-form-item>
                            <el-form-item label="辅料总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f70)}}</div>
                            </el-form-item>
                            <el-form-item label="包材总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f71)}}</div>
                            </el-form-item>
                            <el-form-item label="加工费总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f72)}}</div>
                            </el-form-item>
                            <el-form-item label="绣花费总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f77)}}</div>
                            </el-form-item>
                            <el-form-item label="预估总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f78)}}</div>
                            </el-form-item>
                        </el-form>
                        <el-form inline class="verify-price-box" label-position="right" label-width="140px" @submit.native.prevent>
                            <el-form-item label="绣花成本总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f62)}}</div>
                            </el-form-item>
                            <el-form-item label="绣花成本加价总价：">
                                <div style="width: 80px;font-weight: bold">{{parseFloat(editForm.f63)}}</div>
                            </el-form-item>
                            <el-form-item label="管理费率：">
                                <el-input-number v-model="editForm.f61" size="mini" controls-position="right" :min="0" :step="0.1" placeholder="0"
                                    :disabled="!isEdit" style="width: 100px;" @change="f61Change"></el-input-number>
                            </el-form-item>
                            <el-form-item label="印花成本总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.printing_price)}}</div>
                            </el-form-item>
                            <el-form-item label="成衣成本总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f64)}}</div>
                            </el-form-item>
                            <el-form-item label="成衣成本加价总价：">
                                <div style="width: 80px;font-weight: bold">{{parseFloat(editForm.f65)}}</div>
                            </el-form-item>
                            <el-form-item label="其他费用总价：">
                                <div style="width: 100px;">{{parseFloat(editForm.f74)}}</div>
                            </el-form-item>
                            <el-form-item label="其他费用加价总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f75)}}</div>
                            </el-form-item>
                            <el-form-item label="成本总价：">
                                <div style="width: 80px;">{{parseFloat(editForm.f66)}}</div>
                            </el-form-item>
                            <el-form-item label="成本加价总价：">
                                <div style="width: 80px;font-weight: bold">{{parseFloat(editForm.f67)}}</div>
                            </el-form-item>
                            <el-form-item label="备注：">
                                <el-input type="textarea" resize="none" :autosize="{minRows:2,maxRows:2}" v-model="editForm.comment" style="width: 450px;" :disabled="!isEdit" placeholder="备注"></el-input>
                            </el-form-item>
                        </el-form>
                    </el-col>
                </el-row>
                <el-tabs type="border-card" v-model="tab" class="verify-tab-box">
                    <el-tab-pane label="物料清单" name="bom_list">
                        <el-table :data="editBomList" style="width: 100%" :max-height="drawerTableHeight" class="detail-table-box" size="mini"
                                  :header-cell-style="editHeaderCellStyle" :summary-method="(param) => getSummaries(param, 'bom')" show-summary>
                            <el-table-column type="index" width="40" label="#"></el-table-column>
                            <el-table-column label="物料类型" prop="materiel_major_category" width="70"></el-table-column>
                            <el-table-column label="物料名称" prop="materiel" width="120" show-overflow-tooltip></el-table-column>
                            <el-table-column label="单位" prop="materiel_major_unit" width="50"></el-table-column>
                            <el-table-column label="部位" prop="part" width="100" show-overflow-tooltip></el-table-column>
                            <el-table-column label="属性" prop="materiel_attribute" show-overflow-tooltip></el-table-column>
                            <el-table-column label="供应商" prop="supplier" width="100" show-overflow-tooltip></el-table-column>
                            <el-table-column label="价格" prop="price" width="80">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.price" size="mini" type="number"
                                             :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 'bom')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="单耗" prop="amount" width="80">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.amount" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 'bom')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="损耗" prop="f56" width="80">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.f56" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 'bom')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="总价" prop="" width="80">
                                <template slot-scope="{row}">
                                    {{ parseFloat(parseFloat((Number(row.price) * Number(row.amount) * Number(row.f56)).toFixed(10)).toFixed(4)) }}
                                </template>
                            </el-table-column>
                            <el-table-column label="加价率(%)" prop="f57" width="80">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.f57" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" @change="detailChange($event, 'bom')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="加价金额" prop="" width="80">
                                <template slot-scope="{row}">
                                    {{ parseFloat(parseFloat((Number(row.price) * Number(row.amount) * Number(row.f56) * Number(row.f57) / 100).toFixed(10)).toFixed(4)) }}
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="加工项目" name="item_list">
                        <el-table :data="editItemList" style="width: 100%" :max-height="drawerTableHeight" class="detail-table-box" size="mini"
                                  :summary-method="(param) => getSummaries(param, 'item')" show-summary>
                            <el-table-column label="删除" width="45" v-if="isEdit" fixed>
                                <template slot-scope="scope">
                                    <el-button size="small" class="el-icon-delete" type="text" @click="delDetailBtn(scope.$index, 'item')"></el-button>
                                </template>
                            </el-table-column>
                            <el-table-column label="费用类型" prop="price_type_id">
                                <template slot="header" slot-scope="scope">
                                    <span>费用类型</span>
                                    <el-button type="text" class="el-icon-circle-plus" :disabled="!isEdit" @click="addDetailBtn('item')" style="margin-left: 4px;"></el-button>
                                </template>
                                <template slot-scope="{row}">
                                    <el-select v-model="row.price_type_id" size="small" :disabled="!isEdit" @change="detailChange(0, 'item')">
                                        <el-option v-for="(item, index) in verifyTypeList" :key="index" :value="item.id" :label="item.name"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="数量" prop="count">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.count" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 'item')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="价格" prop="price">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.price" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 'item')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="总价">
                                <template slot-scope="{row}">
                                    {{parseFloat(parseFloat((Number(row.price) * Number(row.count)).toFixed(10)).toFixed(4))}}
                                </template>
                            </el-table-column>
                            <el-table-column label="加价率(%)" prop="f58">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.f58" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 'item')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="加价金额">
                                <template slot-scope="{row}">
                                    {{parseFloat(parseFloat((Number(row.price) * Number(row.count) * Number(row.f58) / 100).toFixed(10)).toFixed(4))}}
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="绣花BOM" name="t59_list">
                        <el-table :data="editT59List" style="width: 100%" :max-height="drawerTableHeight" class="detail-table-box" size="mini"
                                  :summary-method="(param) => getSummaries(param, 't59')" show-summary>
                            <el-table-column type="index" width="40" label="#"></el-table-column>
                            <el-table-column label="线色" prop="f51"></el-table-column>
                            <el-table-column label="部位" prop="part"></el-table-column>
                            <el-table-column label="针数" prop="f52"></el-table-column>
                            <el-table-column label="换色批次" prop="f53"></el-table-column>
                            <el-table-column label="针数单价" prop="f54"></el-table-column>
                            <el-table-column label="针数计费">
                                <template slot-scope="{row}">
                                    {{parseFloat((Number(row.f52) * Number(row.f54)).toFixed(2))}}
                                </template>
                            </el-table-column>
                            <el-table-column label="其他费用" prop="f55"></el-table-column>
                            <el-table-column label="实际绣花价">
                                <template slot-scope="{row}">
                                    {{parseFloat((Number(row.f52) * Number(row.f54) + Number(row.f55)).toFixed(2))}}
                                </template>
                            </el-table-column>
                            <el-table-column label="加价率(%)" prop="f60">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.f60" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 't59')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="加价金额">
                                <template slot-scope="{row}">
                                    {{parseFloat(((Number(row.f52) * Number(row.f54) + Number(row.f55)) * Number(row.f60) / 100).toFixed(3))}}
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="印花BOM" name="printing_list">
                        <el-table :data="editPrintingList" style="width: 100%" :max-height="drawerTableHeight" class="detail-table-box" size="mini"
                                  :summary-method="(param) => getSummaries(param, 'printing')" show-summary>
                            <el-table-column type="index" width="40" label="#"></el-table-column>
                            <el-table-column label="物料类型" prop="materiel_major_category" width="70"></el-table-column>
                            <el-table-column label="物料分类" prop="materiel_minor_category"show-overflow-tooltip></el-table-column>
                            <el-table-column label="物料编码" prop="materiel_number"></el-table-column>
                            <el-table-column label="物料名称" prop="materiel" show-overflow-tooltip></el-table-column>
                            <el-table-column label="属性" prop="materiel_attribute" show-overflow-tooltip></el-table-column>
                            <el-table-column label="印花部位" prop="part" width="100" show-overflow-tooltip></el-table-column>
                            <el-table-column label="印花" prop="printing" width="100"></el-table-column>
                            <el-table-column label="大货单价" prop="price" width="100">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.price" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="0.1" placeholder="0" @change="detailChange($event, 'printing')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="供应商" prop="supplier"></el-table-column>
                        </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="其他费用" name="t76_list">
                        <el-table :data="editT76List" style="width: 100%" :max-height="drawerTableHeight" class="detail-table-box" size="mini"
                                  :summary-method="(param) => getSummaries(param, 't76')" show-summary>
                            <el-table-column label="删除" width="45" v-if="isEdit" fixed>
                                <template slot-scope="scope">
                                    <el-button size="small" class="el-icon-delete" type="text" @click="delDetailBtn(scope.$index, 't76')"></el-button>
                                </template>
                            </el-table-column>
                            <el-table-column label="费用类型" prop="price_type_id">
                                <template slot="header" slot-scope="scope">
                                    <span>费用类型</span>
                                    <el-button type="text" class="el-icon-circle-plus" :disabled="!isEdit" @click="addDetailBtn('t76')" style="margin-left: 4px;"></el-button>
                                </template>
                                <template slot-scope="{row}">
                                    <el-select v-model="row.price_type_id" size="small" :disabled="!isEdit">
                                        <el-option v-for="(item, index) in verifyTypeList" :key="index" :value="item.id" :label="item.name"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                            <el-table-column label="数量" prop="count">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.count" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="1" placeholder="0" @change="detailChange($event, 't76')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="价格" prop="price">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.price" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="1" placeholder="0" @change="detailChange($event, 't76')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="总价">
                                <template slot-scope="{row}">
                                    {{parseFloat(parseFloat((Number(row.price) * Number(row.count)).toFixed(10)).toFixed(4))}}
                                </template>
                            </el-table-column>
                            <el-table-column label="加价率(%)" prop="f58">
                                <template slot-scope="{row}">
                                    <el-input class="detail-input-item" v-model.trim="row.f58" size="mini" type="number"
                                              :readonly="!isEdit" :min="0" step="1" placeholder="0" @change="detailChange($event, 't76')"></el-input>
                                </template>
                            </el-table-column>
                            <el-table-column label="加价金额">
                                <template slot-scope="{row}">
                                    {{parseFloat(parseFloat((Number(row.price) * Number(row.count) * Number(row.f58) / 100).toFixed(10)).toFixed(4))}}
                                </template>
                            </el-table-column>
                            <el-table-column label="供应商" prop="supplier" width="250">
                                <template slot-scope="{row}">
                                    <el-select v-model="row.supplier" filterable remote placeholder="输入搜索的工厂名称" size="small"
                                               :remote-method="searchFactoryBtn" :disabled="!isEdit" clearable>
                                        <el-option v-for="(item,index) in factoryList" :label="item.factory_name" :value="item.factory_name" :key="index"></el-option>
                                    </el-select>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                </el-tabs>
            </el-row>
            <div style="width: 100%;position: absolute;bottom: 10px;padding: 8px;border-top: 1px #ebeef5 solid;">
                <el-button @click="closeBtn">退 出</el-button>
                <el-button type="primary" v-if="isEdit" @click="saveBtn" :loading="saveLoading" :disabled="editBomList.length==0">
                    {{ saveLoading ? '提交中 ...' : '保 存' }}
                </el-button>
            </div>
        </el-drawer>

        <!--打印-->
        <el-drawer :title="printTitle" :visible.sync="printVisible" :with-header="false" size="1200px" direction="rtl" :wrapperClosable="false"
                   :close-on-press-escape="false">
            <print-design v-if="printData.type=='design'" :printData="printData" :verifyTypeList="verifyTypeList"
                          @close-btn="printVisible=false;printData={}"></print-design>
            <print-supplier v-if="printData.type=='supplier'" :printData="printData" :verifyTypeList="verifyTypeList"
                            @close-btn="printVisible=false;printData={}"></print-supplier>
        </el-drawer>
    </section>
</template>

<script>


import {
    verifyPriceDel,
    verifyPriceDetail,
    verifyPriceList,
    verifyPriceLock, verifyPriceSave,
    verifyPriceStyle
} from "../../../api/soa/verify";
import {copyText, formatDate, numberSubstr} from "../../../libs/tools";
import {ptypeList} from "../../../api/bs/info";
import {factoryList} from "../../../api/produce/factory";
import PrintDesign from "./components/printDesign";
import PrintSupplier from "./components/printSupplier";
import {utilsGetImg64} from "../../../api/tool/utils";

export default {
    name: "soa_pricing_verify",
    components: {PrintSupplier, PrintDesign},
    data() {
        return {
            tableHeight: window.innerHeight - 210,
            selectIndex: 0,
            btnLoading: false,
            loading: false,
            page: 1,
            limit: 20,
            total: 0,
            data: [],
            user: {},
            nodeActions: [],

            form:{type_no: "", number: "", type_name: "", t73_id: "", state: "", creator:""},
            verifyTypeList: [],//核价类型

            saveLoading: false,
            editTitle: "",
            editVisible: false,
            editForm: {},
            styleList: [],
            editItemList: [],
            editBomList: [],
            editPrintingList: [],
            editT59List: [],
            editT76List: [],
            factoryList: [],
            isEdit: 0,
            tab: "bom_list",
            drawerTableHeight: window.innerHeight - 512+"px",

            printTitle: "",
            printData: {},
            printVisible: false,
        }
    },
    created() {
        this.user = this.$store.getters.user;
        this.nodeActions = this.user.node_actions[this.$route.meta.id] ? this.user.node_actions[this.$route.meta.id] : [];
    },
    watch:{
        // 监听路由参数的变化
        '$route.params.verify_price_number': {
            immediate: true,
            handler(val) {
                if(!!val && val != this.form.number){
                    this.$set(this.form, 'number', val);
                    this.searchBtn();
                }
            }
        },
    },
    methods: {
        //打印按钮
        printBtn(command){
            let commands = command.split(":");
            switch (commands[0]){
                case "DESIGN":
                    this.printTitle = "成本预估核价单(设计部专用)";
                    this.printData = {
                        type: 'design',
                        rate: parseFloat(commands[1]),
                        editForm: this.editForm,
                        editItemList: this.editItemList,
                        editBomList: this.editBomList,
                        editPrintingList: this.editPrintingList,
                        editT59List: this.editT59List,
                        editT76List: this.editT76List
                    };
                    this.printVisible = true;
                    break;
                case "SUPPLIER":
                    this.btnLoading = true;
                    utilsGetImg64({img: this.editForm.img}).then((res) => {
                        this.btnLoading = false;
                        this.editForm.img_64 = res.data;
                        this.printTitle = "加工厂核价单";
                        this.printData = {
                            type: 'supplier',
                            editForm: this.editForm,
                            editItemList: this.editItemList,
                            editBomList: this.editBomList,
                            editPrintingList: this.editPrintingList,
                            editT59List: this.editT59List,
                            editT76List: this.editT76List
                        };
                        this.printVisible = true;
                    })
                    break;
            }
        },
        //搜索款号
        searchTypeNoBtn(val){
            if(val == "" || val.length < 4){
                return;
            }
            verifyPriceStyle({style_number: val}).then((res) =>{
                this.styleList = res.data;
            }).catch(() => {

            })
        },
        //搜索加工厂
        searchFactoryBtn(val){
            if(val == ""){
                return;
            }
            this.getFactoryData(val);
        },
        getFactoryData(name){
            factoryList({page: 1, limit: 200, factory_name: name, status: 0}).then((res) =>{
                this.factoryList = res.data.data;
            })
        },
        //搜索按钮
        searchBtn() {
            this.page = 1;
            this.getData();
        },
        //翻页
        pageChange(page) {
            this.page = page;
            this.getData();
        },
        //获取数据
        getData() {
            let param = {
                page: this.page,
                limit: this.limit
            };
            param = Object.assign(param, this.form);
            this.loading = true;
            verifyPriceList(param).then((res) => {
                this.loading = false;
                this.total = res.data.total;
                this.data = res.data.data;
            }).catch(() => {
                this.loading = false;
            });
        },
        //获取核价类型
        getVerifyType(){
            ptypeList({page: 1, limit: 100}).then((res) =>{
                this.verifyTypeList = res.data.data;
            })
        },
        headerCellStyle(row) {
            if (["管理费率","绣花成本加价总价","成衣成本加价总价","成本加价总价","其他费用加价总价"].includes(row.column.label)) {
                return {background: "#F0F9EB"};
            }else{
                return {background: "#F3F4F7"}
            }
        },
        editHeaderCellStyle(row){
            if (["价格","单耗","损耗","总价","加价率(%)", "加价金额"].includes(row.column.label)) {
                return {background: "#F0F9EB"};
            }else{
                return {background: "#F3F4F7"}
            }
        },
        copyBtn(classTag, content){
            copyText(classTag, content);
            this.$message.success("复制成功: "+content)
        },
        //跳转
        linkTo(val, name){
            switch (name){
                case "pages_designEd":
                    this.$router.push({
                        name: name,
                        params: {id: val, isEdit: 0}
                    });
                    break;
            }
        },
        //明细合计
        getSummaries(param, type){
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "";
                    return;
                }
                switch (type){
                    case "bom"://物料清单
                        if(column.label == '总价'){
                            sums[index] = 0;
                            data.forEach(item => {
                                let price = parseFloat(parseFloat((Number(item.price) * Number(item.amount) * Number(item.f56)).toFixed(10)).toFixed(4));
                                sums[index] += price;
                            })
                            sums[index] = parseFloat(sums[index].toFixed(4));
                        } else if(column.label == '加价金额'){
                            sums[index] = 0;
                            data.forEach(item => {
                                let price = parseFloat(parseFloat((Number(item.price) * Number(item.amount) * Number(item.f56) * Number(item.f57) /100).toFixed(10)).toFixed(4));
                                sums[index] += price;
                            })
                            sums[index] = parseFloat(sums[index].toFixed(4));
                        }else {
                            sums[index] = "";
                        }
                        break;
                    case "item"://加工项目
                        if(column.label == '总价'){
                            sums[index] = 0;
                            data.forEach(item => {
                                let price = parseFloat(parseFloat((Number(item.price) * Number(item.count)).toFixed(10)).toFixed(4));
                                sums[index] += price;
                            })
                            sums[index] = parseFloat(sums[index].toFixed(4));
                        } else if(column.label == '加价金额'){
                            sums[index] = 0;
                            data.forEach(item => {
                                let price = parseFloat(parseFloat((Number(item.price) * Number(item.count) * Number(item.f58) /100).toFixed(10)).toFixed(4));
                                sums[index] += price;
                            })
                            sums[index] = parseFloat(sums[index].toFixed(4));
                        }else {
                            sums[index] = "";
                        }
                        break;
                    case "t59"://绣花
                        if(column.label == '实际绣花价'){
                            sums[index] = 0;
                            data.forEach(item => {
                                sums[index] += Number(item.f52) * Number(item.f54) + Number(item.f55);
                            })
                            sums[index] = parseFloat(sums[index].toFixed(2));
                        } else if(column.label == '加价金额'){
                            sums[index] = 0;
                            data.forEach(item => {
                                let price = parseFloat(((Number(item.f52) * Number(item.f54) + Number(item.f55)) * Number(item.f60) /100).toFixed(3));
                                sums[index] += price;
                            })
                            sums[index] = parseFloat(sums[index].toFixed(3));
                        }else {
                            sums[index] = "";
                        }
                        break;
                    case "printing"://印花
                        if(column.label == '大货单价'){
                            sums[index] = 0;
                            data.forEach(item => {
                                sums[index] += Number(item.price);
                            })
                            sums[index] = parseFloat(sums[index]);
                        } else {
                            sums[index] = "";
                        }
                        break;
                    case "t76"://其他费用
                        if(column.label == '总价'){
                            sums[index] = 0;
                            data.forEach(item => {
                                let price = parseFloat(parseFloat((Number(item.price) * Number(item.count)).toFixed(10)).toFixed(4));
                                sums[index] += price;
                            })
                            sums[index] = parseFloat(sums[index].toFixed(4));
                        } else if(column.label == '加价金额'){
                            sums[index] = 0;
                            data.forEach(item => {
                                let price = parseFloat(parseFloat((Number(item.price) * Number(item.count) * Number(item.f58) /100).toFixed(10)).toFixed(4));
                                sums[index] += price;
                            })
                            sums[index] = parseFloat(sums[index].toFixed(4));
                        }else {
                            sums[index] = "";
                        }
                        break;
                }
            });
            return sums;
        },
        //管理费率变动
        f61Change(val){
            let price = 0;
            let pricePlus = 0;
            let f72 = 0;
            let f72Plus = 0;
            this.editBomList.forEach(item => {
                price += parseFloat(parseFloat((Number(item.price) * Number(item.amount) * Number(item.f56)).toFixed(10)).toFixed(4));
                pricePlus += parseFloat(parseFloat((Number(item.price) * Number(item.amount) * Number(item.f56) * Number(item.f57) /100).toFixed(10)).toFixed(4));
            });
            this.editItemList.forEach(item => {
                f72 += parseFloat(parseFloat((Number(item.price) * Number(item.count)).toFixed(10)).toFixed(4));
                f72Plus += parseFloat(parseFloat((Number(item.price) * Number(item.count) * Number(item.f58) /100).toFixed(10)).toFixed(4));
            });
            price = parseFloat(price.toFixed(4));
            pricePlus = parseFloat(pricePlus.toFixed(4));
            f72 = parseFloat(f72.toFixed(4));
            f72Plus = parseFloat(f72Plus.toFixed(4));
            this.editForm.f78 = numberSubstr(parseFloat(this.editForm.f69) + parseFloat(this.editForm.f70) +
                parseFloat(this.editForm.f71) + f72, 2);//预估总价
            this.editForm.f64 = numberSubstr((price + f72) * Number(val), 2);//成衣成本总价
            this.editForm.f65 = numberSubstr((price + f72 + pricePlus + f72Plus) * Number(val), 2);//成衣成本加价总价
            this.editForm.f66 = parseFloat((parseFloat(this.editForm.f62) + this.editForm.f64).toFixed(2));//成本总价
            this.editForm.f67 = parseFloat((parseFloat(this.editForm.f63) + this.editForm.f65).toFixed(2));//成本加价总价
        },
        //物料清单明细变动
        detailChange(val, type){
            switch (type){
                case "bom"://物料清单
                    let f69 = 0, f70 = 0, f71 = 0;
                    this.editBomList.forEach(item => {
                        let price = parseFloat(parseFloat((Number(item.price) * Number(item.amount) * Number(item.f56)).toFixed(10)).toFixed(4));
                        if(item.materiel_major_category == '主料'){
                            f69 += price;
                        }
                        if(item.materiel_major_category == '辅料'){
                            f70 += price;
                        }
                        if(item.materiel_major_category == '特殊工艺'){
                            f71 += price;
                        }
                    });
                    this.editForm.f69 = numberSubstr(f69, 2);//主料总价
                    this.editForm.f70 = numberSubstr(f70, 2);//辅料总价
                    this.editForm.f71 = numberSubstr(f71, 2);//包材总价
                    this.f61Change(this.editForm.f61);
                    break;
                case "item"://加工项目
                    let f72 = 0, f77 = 0;
                    this.editItemList.forEach(item => {
                        if(item.price_type_id == 1){
                            f72 += parseFloat(parseFloat((Number(item.price) * Number(item.count)).toFixed(10)).toFixed(4));
                        }
                        if(item.price_type_id == 2){
                            f77 += parseFloat(parseFloat((Number(item.price) * Number(item.count)).toFixed(10)).toFixed(4));
                        }
                    });
                    this.editForm.f72 = numberSubstr(parseFloat(f72.toFixed(4)), 2);
                    this.editForm.f77 = numberSubstr(parseFloat(f77.toFixed(4)), 2);
                    this.f61Change(this.editForm.f61);
                    break;
                case "t59"://绣花
                    let f62Plus = 0, f62 = 0;
                    this.editT59List.forEach(item => {
                        f62 += parseFloat((Number(item.f52) * Number(item.f54) + Number(item.f55)).toFixed(2));
                        f62Plus += parseFloat(((Number(item.f52) * Number(item.f54) + Number(item.f55)) * Number(item.f60) /100).toFixed(3));
                    });
                    this.editForm.f62 = parseFloat(f62.toFixed(2));
                    this.editForm.f63 = numberSubstr(parseFloat(f62) + parseFloat(f62Plus.toFixed(3)), 2);
                    this.f61Change(this.editForm.f61);
                    break;
                case "printing"://印花
                    let price = 0;
                    this.editPrintingList.forEach(item => {
                        price += Number(item.price);
                    })
                    this.editForm.printing_price = parseFloat(numberSubstr(price, 2));
                    break;
                case "t76"://其他费用
                    let f74 = 0, f74Plus = 0;
                    this.editT76List.forEach(item => {
                        f74 += parseFloat(parseFloat((Number(item.price) * Number(item.count)).toFixed(10)).toFixed(4));
                        f74Plus += parseFloat(parseFloat((Number(item.price) * Number(item.count) * Number(item.f58) /100).toFixed(10)).toFixed(4));
                    });
                    this.editForm.f74 = numberSubstr(f74, 2);
                    this.editForm.f75 = numberSubstr((f74 + f74Plus).toFixed(2), 2);
                    break;
            }
        },
        //明细新增
        addDetailBtn(type){
            switch (type){
                case 'item'://加工项目
                    this.editItemList.push({
                        count: "", price: "", f58: "", verify_price_id: this.editForm.id ? this.editForm.id : "", price_type_id: ""
                    });
                    break;
                case 't76'://其他费用
                    this.editT76List.push({
                        count: "", price: "", f58: "", supplier: "", supplier_id: 0, price_type_id: "", verify_price_id: this.editForm.id ? this.editForm.id : ""
                    });
                    break;
            }
        },
        //明细删除
        delDetailBtn(index, type){
            this.$confirm(`确认删除吗？`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                switch (type) {
                    case 'item'://加工项目
                        this.editItemList.splice(index, 1);
                        this.detailChange(0, type)
                        break;
                    case 't76'://其他费用
                        this.editT76List.splice(index, 1);
                        this.detailChange(0, type)
                        break;
                }
            }).catch(() => {

            })
        },
        editBtn(row){
            this.loading = true;
            verifyPriceDetail({id: row.id}).then((res) => {
                this.loading = false;
                this.editTitle = res.data.data.state == 0 && this.nodeActions.includes("edit") ? "核价单：编辑" : "核价单：查看";
                this.isEdit = res.data.data.state == 0 && this.nodeActions.includes("edit") ? 1 : 0;
                this.editForm = res.data.data;
                this.editForm.f61 = parseFloat(this.editForm.f61);
                this.editItemList = res.data.item_list;
                this.editBomList = res.data.bom_list;
                this.editPrintingList = res.data.printing_list;
                this.editT59List = res.data.t59_list;
                this.editT76List = res.data.t76_list;
                this.tab = "bom_list";
                this.editVisible = true;
            }).catch(() => {
                this.loading = false;
            });
        },
        //更多操作
        actionBtn(command, row){
            switch (command){
                case "LOCK":
                case "UNLOCK":
                    let msg  = command == "LOCK" ? `【锁定】订单：${row.number}, 是否确认` : `【解锁】订单：${row.number}, 是否确认`;
                    let state = command == "LOCK" ? 1 : 0;
                    this.$confirm(msg, "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        this.loading = true;
                        verifyPriceLock({id: row.id, state: state}).then((res) =>{
                            this.loading = false;
                            if(res.code === 0){
                                this.$message.success(state == 1 ? "锁定成功" : "解锁成功");
                                this.getData();
                            }else{
                                this.$message.error(res.msg);
                            }
                        }).catch(() =>{
                            this.loading = false;
                        })
                    }).catch(() => {

                    });
                    break;
                case "DEL":
                    this.$confirm(`【删除】核价单：${row.number}, 是否确认`, "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        this.loading = true;
                        verifyPriceDel({id: row.id}).then((res) =>{
                            this.loading = false;
                            if(res.code === 0){
                                this.$message.success("删除成功");
                                this.getData();
                            }else{
                                this.$message.error(res.msg);
                            }
                        }).catch(() =>{
                            this.loading = false;
                        })
                    }).catch(() => {

                    });
                    break;
                case "COPY":
                    this.loading = true;
                    this.editForm = {};
                    this.editItemList = [];
                    this.editBomList = [];
                    this.editPrintingList = [];
                    this.editT59List = [];
                    this.editT76List = [];
                    verifyPriceDetail({id: row.id}).then((res) => {
                        this.loading = false;
                        delete res.data.data.state;
                        delete res.data.data.id;
                        delete res.data.data.number;
                        this.editTitle = this.nodeActions.includes("edit") ? "核价单：复制新增" : "核价单：查看";
                        this.isEdit = this.nodeActions.includes("edit") ? 1 : 0;
                        this.editForm = res.data.data;
                        this.editForm.f61 = parseFloat(this.editForm.f61);
                        this.editForm.state = 0;
                        res.data.item_list.forEach(item => {
                            delete item.id;
                            delete item.verify_price_id;
                            this.editItemList.push(item);
                        });
                        res.data.bom_list.forEach(item => {
                            delete item.id;
                            delete item.verify_price_id;
                            this.editBomList.push(item);
                        });
                        res.data.printing_list.forEach(item => {
                            delete item.id;
                            delete item.verify_price_id;
                            this.editPrintingList.push(item);
                        })
                        res.data.t59_list.forEach(item => {
                            delete item.id;
                            delete item.verify_price_id;
                            this.editT59List.push(item);
                        });
                        res.data.t76_list.forEach(item => {
                            delete item.id;
                            delete item.verify_price_id;
                            this.editT76List.push(item);
                        });
                        this.tab = "bom_list";
                        //console.log(this.editForm, this.editItemList, this.editBomList, this.editPrintingList, this.editT59List, this.editT76List);
                        this.editVisible = true;
                    }).catch(() => {
                        this.loading = false;
                    });
                    break;
            }
        },
        closeBtn(){
            this.isEdit = 0;
            this.editVisible = false;
            this.editForm = {};
            this.editItemList = [];
            this.editBomList = [];
            this.editPrintingList = [];
            this.editT59List = [];
            this.editT76List = [];
        },
        addBtn(){
            this.editVisible = true;
            this.editTitle = "核价单：新增";
            this.editForm = {
                currency_id: 1,
                state: 0,
                comment: "",
                f61: 1.1,
                f62: 0,
                f63: 0,
                f64: 0,
                f65: 0,
                f66: 0,
                f67: 0,
                f69: 0,
                f70: 0,
                f71: 0,
                f72: 0,
                f74: 0,
                f75: 0,
                f77: 0,
                f78: 0,
                printing_price: 0,
            };
            this.editItemList = [];
            this.editBomList = [];
            this.editPrintingList = [];
            this.editT59List = [];
            this.editT76List = [];
            this.isEdit = 1;
        },
        typeNoChangeBtn(val){
            this.addBtn();
            let styleArr = val.split(" ");
            this.styleList.forEach(item => {
                if(item.style.number == styleArr[0] && item.colour == styleArr[2] && item.label == styleArr[1]){
                    this.editForm = Object.assign(this.editForm,
                        {
                            img: item.style.img,
                            import_number: item.style.number,
                            import_id: item.style.id,
                            style_number: item.style.number,
                            style: item.style.name,
                            colour: styleArr[2],
                            product_category_id: item.style.product_category_id,
                            product_category: item.style.product_category,
                            style_detail_category_id: item.style.detail_category_id,
                            style_detail_category: item.style.detail_category,
                        }
                    );
                    //物料清单
                    item.bom.forEach(bomItem => {
                       this.editBomList.push({
                           materiel_id: bomItem.materiel_id,
                           materiel: bomItem.materiel,
                           materiel_major_category: bomItem.materiel_major_category,
                           materiel_major_unit:bomItem.materiel_major_unit,
                           materiel_attribute:bomItem.materiel_attribute,
                           materiel_supply_type_id: 2,
                           part: bomItem.part,
                           amount: parseFloat(bomItem.amount),
                           price: parseFloat(bomItem.price),
                           supplier_id: bomItem.supplier_id,
                           supplier: bomItem.supplier,
                           f56: 1,
                           f57: ""
                       })
                    });
                    if(this.editBomList.length > 0){
                        this.detailChange(0, 'bom');
                    }
                    //绣花BOM
                    item.xh_bom.forEach(xhItem => {
                        this.editT59List.push({
                            f51: xhItem.f51,
                            part: xhItem.part,
                            f52: xhItem.f52,
                            f53: xhItem.f53,
                            f54: parseFloat(xhItem.f54),
                            f55: parseFloat(xhItem.f55),
                            f60: 10
                        });
                    });
                    if(this.editT59List.length > 0){
                        this.detailChange(0, 't59');
                    }
                    //印花BOM
                    item.printing_bom.forEach(printItem => {
                        this.editPrintingList.push({
                            part: printItem.part,
                            price: parseFloat(printItem.price),
                            materiel_id: printItem.materiel_id,
                            materiel_number: printItem.materiel_number,
                            materiel: printItem.materiel,
                            materiel_major_category: printItem.materiel_major_category,
                            materiel_minor_category: printItem.materiel_minor_category,
                            materiel_attribute: printItem.materiel_attribute,
                            printing: printItem.printing,
                            supplier_id: printItem.supplier_id,
                            supplier: printItem.supplier
                        });
                    });
                    if(this.editPrintingList.length > 0){
                        this.detailChange(0, 'printing')
                    }
                }
            })

        },
        saveBtn(){
            if(this.editBomList.length == 0 || !this.editForm.t73_id){
                this.$message.warning("缺失必填项");return;
            }
            this.saveLoading = true;
            let obj = {
                form: JSON.stringify(this.editForm),
                bom_list: JSON.stringify(this.editBomList),
                item_list: JSON.stringify(this.editItemList),
                t59_list: JSON.stringify(this.editT59List),
                t76_list: JSON.stringify(this.editT76List),
                printing_list: JSON.stringify(this.editPrintingList)
            };
            verifyPriceSave(obj).then((res) => {
                this.saveLoading = false;
                if(res.code === 0){
                    this.$message.success("保存成功");
                    this.editVisible = false;
                    this.getData();
                }else{
                    this.$message.error(res.msg);
                }
            }).catch(() => {
                this.saveLoading = false;
            })
        },
    },
    mounted() {
        this.searchBtn();
        this.getVerifyType();
        this.getFactoryData("");
    }
}
</script>

<style scoped>
.el-image /deep/ .el-icon-circle-close:before{
    color: white;
}
.edit-item-form /deep/ .el-form-item__label{
    color: #409eff;
}

.verify-price-box{
    border-top: 1px solid #e8eaec;
    padding-top: 8px;
}
.verify-price-box /deep/ .el-form-item__label{
    line-height: 25px;
}
.verify-price-box /deep/ .el-form-item__content{
    line-height: 25px;
}

.verify-tab-box /deep/ .el-tabs__content{
    padding: unset;
}

.detail-table-box /deep/ .detail-input-item .el-input__inner {
    padding: 0 !important;
}
.detail-table-box /deep/ .el-input__inner {
    border: none !important;
}

.more-btn /deep/ .el-badge__content.is-fixed.is-dot{
    top: 5px;
}
</style>
